home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / MacMud / Unix / rpc⁄svc.h < prev    next >
Encoding:
Text File  |  1990-04-09  |  7.2 KB  |  254 lines  |  [TEXT/????]

  1. /*      @(#)svc.h 1.1 86/09/24 SMI      *
  2.  
  3. /*
  4.  * svc.h, Server-side remote procedure call interface.
  5.  *
  6.  * Copyright (C) 1984, Sun Microsystems, Inc.
  7.  */
  8.  
  9. #ifndef __SVC_HEADER__
  10. #define __SVC_HEADER__
  11.  
  12. /*
  13.  * This interface must manage two items concerning remote procedure calling:
  14.  *
  15.  * 1) An arbitrary number of transport connections upon which rpc requests
  16.  * are received.  The two most notable transports are TCP and UDP;  they are
  17.  * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
  18.  * they in turn call xprt_register and xprt_unregister.
  19.  *
  20.  * 2) An arbitrary number of locally registered services.  Services are
  21.  * described by the following four data: program number, version number,
  22.  * "service dispatch" function, a transport handle, and a boolean that
  23.  * indicates whether or not the exported program should be registered with a
  24.  * local binder service;  if true the program's number and version and the
  25.  * port number from the transport handle are registered with the binder.
  26.  * These data are registered with the rpc svc system via svc_register.
  27.  *
  28.  * A service's dispatch function is called whenever an rpc request comes in
  29.  * on a transport.  The request's program and version numbers must match
  30.  * those of the registered service.  The dispatch function is passed two
  31.  * parameters, struct svc_req * and SVCXPRT *, defined below.
  32.  */
  33.  
  34. enum xprt_stat {
  35.     XPRT_DIED,
  36.     XPRT_MOREREQS,
  37.     XPRT_IDLE,
  38.     XPRT_4BYTES=0x7fffffff
  39. };
  40.  
  41. /*
  42.  * Server side transport handle
  43.  */
  44. typedef struct {
  45. #ifdef KERNEL
  46.     struct socket    *xp_sock;
  47. #else
  48.     int        xp_sock;
  49. #endif
  50.     u_short        xp_port;     /* associated port number */
  51.     struct xp_ops {
  52.         bool_t    (*xp_recv)();     /* receive incomming requests */
  53.         enum xprt_stat (*xp_stat)(); /* get transport status */
  54.         bool_t    (*xp_getargs)(); /* get arguments */
  55.         bool_t    (*xp_reply)();     /* send reply */
  56.         bool_t    (*xp_freeargs)();/* free mem allocated for args */
  57.         void    (*xp_destroy)(); /* destroy this struct */
  58.     } *xp_ops;
  59.     int        xp_addrlen;     /* length of remote address */
  60.     struct sockaddr_in xp_raddr;     /* remote address */
  61.     struct opaque_auth xp_verf;     /* raw response verifier */
  62.     caddr_t        xp_p1;         /* private */
  63.     caddr_t        xp_p2;         /* private */
  64. } SVCXPRT;
  65.  
  66. /*
  67.  *  Approved way of getting address of caller
  68.  */
  69. #define svc_getcaller(x) (&(x)->xp_raddr)
  70.  
  71. /*
  72.  * Operations defined on an SVCXPRT handle
  73.  *
  74.  * SVCXPRT        *xprt;
  75.  * struct rpc_msg    *msg;
  76.  * xdrproc_t         xargs;
  77.  * caddr_t         argsp;
  78.  */
  79. #define SVC_RECV(xprt, msg)                \
  80.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  81. #define svc_recv(xprt, msg)                \
  82.     (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
  83.  
  84. #define SVC_STAT(xprt)                    \
  85.     (*(xprt)->xp_ops->xp_stat)(xprt)
  86. #define svc_stat(xprt)                    \
  87.     (*(xprt)->xp_ops->xp_stat)(xprt)
  88.  
  89. #define SVC_GETARGS(xprt, xargs, argsp)            \
  90.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  91. #define svc_getargs(xprt, xargs, argsp)            \
  92.     (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
  93.  
  94. #define SVC_REPLY(xprt, msg)                \
  95.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  96. #define svc_reply(xprt, msg)                \
  97.     (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
  98.  
  99. #define SVC_FREEARGS(xprt, xargs, argsp)        \
  100.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  101. #define svc_freeargs(xprt, xargs, argsp)        \
  102.     (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
  103.  
  104. #define SVC_DESTROY(xprt)                \
  105.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  106. #define svc_destroy(xprt)                \
  107.     (*(xprt)->xp_ops->xp_destroy)(xprt)
  108.  
  109.  
  110. /*
  111.  * Service request
  112.  */
  113. struct svc_req {
  114.     u_long        rq_prog;    /* service program number */
  115.     u_long        rq_vers;    /* service protocol version */
  116.     u_long        rq_proc;    /* the desired procedure */
  117.     struct opaque_auth rq_cred;    /* raw creds from the wire */
  118.     caddr_t        rq_clntcred;    /* read only cooked cred */
  119.     SVCXPRT    *rq_xprt;        /* associated transport */
  120. };
  121.  
  122.  
  123. /*
  124.  * Service registration
  125.  *
  126.  * svc_register(xprt, prog, vers, dispatch, protocol)
  127.  *    SVCXPRT *xprt;
  128.  *    u_long prog;
  129.  *    u_long vers;
  130.  *    void (*dispatch)();
  131.  *    int protocol;  /* like TCP or UDP, zero means do not register 
  132.  */
  133. extern bool_t    svc_register();
  134.  
  135. /*
  136.  * Service un-registration
  137.  *
  138.  * svc_unregister(prog, vers)
  139.  *    u_long prog;
  140.  *    u_long vers;
  141.  */
  142. extern void    svc_unregister();
  143.  
  144. /*
  145.  * Transport registration.
  146.  *
  147.  * xprt_register(xprt)
  148.  *    SVCXPRT *xprt;
  149.  */
  150. extern void    xprt_register();
  151.  
  152. #ifndef KERNEL
  153. /*
  154.  * Transport un-register
  155.  *
  156.  * xprt_unregister(xprt)
  157.  *    SVCXPRT *xprt;
  158.  */
  159. extern void    xprt_unregister();
  160. #endif !KERNEL
  161.  
  162.  
  163. /*
  164.  * When the service routine is called, it must first check to see if it
  165.  * knows about the procedure;  if not, it should call svcerr_noproc
  166.  * and return.  If so, it should deserialize its arguments via 
  167.  * SVC_GETARGS (defined above).  If the deserialization does not work,
  168.  * svcerr_decode should be called followed by a return.  Successful
  169.  * decoding of the arguments should be followed the execution of the
  170.  * procedure's code and a call to svc_sendreply.
  171.  *
  172.  * Also, if the service refuses to execute the procedure due to too-
  173.  * weak authentication parameters, svcerr_weakauth should be called.
  174.  * Note: do not confuse access-control failure with weak authentication!
  175.  *
  176.  * NB: In pure implementations of rpc, the caller always waits for a reply
  177.  * msg.  This message is sent when svc_sendreply is called.  
  178.  * Therefore pure service implementations should always call
  179.  * svc_sendreply even if the function logically returns void;  use
  180.  * xdr.h - xdr_void for the xdr routine.  HOWEVER, tcp based rpc allows
  181.  * for the abuse of pure rpc via batched calling or pipelining.  In the
  182.  * case of a batched call, svc_sendreply should NOT be called since
  183.  * this would send a return message, which is what batching tries to avoid.
  184.  * It is the service/protocol writer's responsibility to know which calls are
  185.  * batched and which are not.  Warning: responding to batch calls may
  186.  * deadlock the caller and server processes!
  187.  */
  188.  
  189. extern bool_t  svc_sendreply();
  190. extern void    svcerr_decode();
  191. extern void    svcerr_weakauth();
  192. extern void    svcerr_noproc();
  193.  
  194. /*
  195.  * Lowest level dispatching -OR- who owns this process anyway.
  196.  * Somebody has to wait for incoming requests and then call the correct
  197.  * service routine.  The routine svc_run does infinite waiting; i.e.,
  198.  * svc_run never returns.
  199.  * Since another (co-existant) package may wish to selectively wait for
  200.  * incoming calls or other events outside of the rpc architecture, the
  201.  * routine svc_getreq is provided.  It must be passed readfds, the
  202.  * "in-place" results of a select system call (see select, section 2).
  203.  */
  204.  
  205. #ifndef KERNEL
  206. /* dynamic; must be inspected before each call to select */
  207. extern int svc_fds;
  208.  
  209. /*
  210.  * a small program implemented by the svc_rpc implementation itself;
  211.  * also see clnt.h for protocol numbers.
  212.  */
  213. extern void rpctest_service();
  214. #endif !KERNEL
  215.  
  216. extern void    svc_getreq();
  217. extern void    svc_run();      /* never returns */
  218.  
  219. /*
  220.  * Socket to use on svcxxx_create call to get default socket
  221.  */
  222. #define    RPC_ANYSOCK    -1
  223.  
  224. /*
  225.  * These are the existing service side transport implementations
  226.  */
  227.  
  228. #ifndef KERNEL
  229. /*
  230.  * Memory based rpc for testing and timing.
  231.  */
  232. extern SVCXPRT *svcraw_create();
  233.  
  234. /*
  235.  * Udp based rpc.
  236.  */
  237. extern SVCXPRT *svcudp_create();
  238. extern SVCXPRT *svcudp_bufcreate();
  239.  
  240. /*
  241.  * Tcp based rpc.
  242.  */
  243. extern SVCXPRT *svctcp_create();
  244.  
  245. #else
  246.  
  247. /*
  248.  * Kernel udp based rpc.
  249.  */
  250. extern SVCXPRT *svckudp_create();
  251. #endif !KERNEL
  252.  
  253. #endif !__SVC_HEADER__
  254.